<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/6/22
  Time: 9:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%>
<html>
<body>
<table align="center" width="70%" border="1">
    <form method="post">
        ID:<input type="number" name="id"><br>
        账号：<input type="text" name="name"><br>
        部门号：<input type="number" name="deptId"><br>
        工资：<input type="password" name="salary"><br>
        <input type="submit" value="提交">
    </form>

    <%  int id=request.getIntHeader("id");
        String name=request.getParameter("name");
        int deptId=request.getIntHeader("deptId");
        float salary=request.getDateHeader("salary");
        Class.forName("com.mysql.jdbc.Driver");
        String URL="jdbc:mysql://localhost:3306/user";
        Connection con=DriverManager.getConnection(URL,"root","ljmspace");
        String sql="insert into test1 values(?,?,?,?)";
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setInt(1,id);
        ps.setString(2,name);
        ps.setInt(3,deptId);
        ps.setFloat(4,salary);

        int i=ps.executeUpdate(sql);
        while(i>0){
    %>
    out.print("数据插入成功！");
    <%
        }
        ps.close();
        con.close();
    %>
</table>
</body>
</html>
